<?php

if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
 * 公告模型类
 */
class Announce_model extends CI_Model
{

	/**
	 * 获取一条信息
	 */
	public function get($announceid)
	{
		$query = $this->db->get_where('common_announce', array('announceid' => $announceid));
		$row = $query->row_array();
		return $row;
	}

	/**
	 * 获取全部信息（根据条件）
	 */
	public function get_all()
	{
		$query = $this->db->order_by('vieworder ASC')->get('common_announce');
		$result = $query->result_array();
		return $result;
	}

	/**
	 * 插入
	 */
	public function insert($data)
	{
		$this->db->insert('common_announce', $data);
		return $this->db->insert_id();
	}

	/**
	 * 更新
	 */
	public function update($data)
	{
		$id = 0;

		if ($data['announceid'])
		{
			$this->db->where('announceid', $data['announceid']);
			$this->db->update('common_announce', $data);

			$id = $data['announceid'];
		}

		return $id;
	}

	/**
	 * 批量更新
	 */
	public function update_batch($data)
	{
		if (is_array($data) && count($data > 0))
		{
			$this->db->update_batch('common_announce', $data, 'announceid');
		}
	}

	/**
	 * 删除
	 */
	public function delete($announceid)
	{
		$this->db->where('announceid', $announceid);
		$this->db->delete('common_announce');
	}

	/**
	 * 获取所有信息（分页显示）
	 *
	 * @param $where array
	 * @param $limit int
	 * @param $offset int
	 * @param $orderby string ('uid DESC, created ASC')
	 * @return array
	 */
	public function get_all_list($where = FALSE, $limit = FALSE, $offset = FALSE, $orderby = FALSE)
	{
		$this->_where_list($where);
		$this->db->order_by($orderby);
		$this->db->limit($limit, $offset);
		$result = $this->db->get('common_announce')->result_array();
		return $result;
	}

	public function count_all_list($where)
	{
		$this->_where_list($where);
		return $this->db->count_all_results('common_announce');
	}

	private function _where_list($where)
	{
		$this->db->where($where);
	}
}

/* End of file link_model.php */
/* Location: ./application/models/link_model.php */
